package com.cskaoyan;


import java.sql.*;

/**
 * 创建日期: 2022/06/08 09:53
 *
 * @author ciggar
 */
public class Main {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        // 注册驱动
        Class.forName("com.mysql.jdbc.Driver");

        // 获取连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/41th?useSSL=false&characterEncoding=utf8",
                "root","123456");


        // 获取statement
        Statement statement = connection.createStatement();


        // 执行SQL语句
        ResultSet resultSet = statement.executeQuery("select * from cskaoyan");

        // 解析结果集
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String teacherName = resultSet.getString("teacher_name");

            System.out.println("id:" + id + ", teacherName:" + teacherName);
        }

        // 关闭资源
        resultSet.close();
        statement.close();
        connection.close();
    }
}
